package com.text.textRecognition.entity.response;

import lombok.Data;

import java.io.Serializable;

@Data
public class ApiResponse<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    protected Integer code = 200;
    protected String msg = "请求成功";
    private T data;

    public ApiResponse() {
    }

    public ApiResponse(T data) {
        this.data = data;
    }

    public ApiResponse(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> ApiResponse<T> success(T data) {
        ApiResponse<T> result = new ApiResponse(data);
        return result;
    }

    public static <T> ApiResponse<T> success() {
        ApiResponse<T> result = new ApiResponse();
        return result;
    }

    public static <T> ApiResponse<T> fail(T data) {
        ApiResponse<T> result = new ApiResponse(data);
        return result;
    }

    public static <T> ApiResponse<T> fail(Integer code, String msg) {
        ApiResponse<T> result = new ApiResponse(code, msg);
        return result;
    }

}
